package com.scrcu.core.batch.biz;

import com.boarsoft.common.Util;
import com.scrcu.core.batch.dao.SqlSessionDao;
import com.scrcu.core.batch.entity.BatchApp;
import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collections;
import java.util.List;

@Component
public class BatchAppBizImpl extends SqlSessionDao implements BatchAppBiz {

	public BatchAppBizImpl(SqlSession dao) {
		super(dao);
	}

	@Override
	@Transactional(readOnly = true)
	public BatchApp get(String addr) {
		return dao.selectOne("com.scrcu.core.batch.BatchApp.selectByAddr", addr);
	}

	@Override
	@Transactional
	public Object save(BatchApp o) {
		if (Util.strIsEmpty(o.getAddr())) {
			throw new RuntimeException("addr cannot be null");
		} else {
			return dao.insert("com.scrcu.core.batch.BatchApp.insertSelctive",o);
		}
	}

	@Override
	@Transactional
	public void delete(String addr) {
		dao.delete("com.scrcu.core.batch.BatchApp.deleteByAddr", addr);
	}

	@Override
	@Transactional(readOnly = true)
	public List<BatchApp> list() {
		return dao.selectList("com.scrcu.core.batch.BatchApp.selectForList", Collections.emptyMap());
	}
}
